package com.dragon.mmochat.model.object;

import com.dragon.mmochat.MmochatConstant;
import com.dragon.mmochat.model.battle.MmochatBattle;
import com.dragon.mmochat.model.enumType.MmochatDrugType;
import com.dragon.mmochat.model.enumType.MmochatObjectType;
import com.dragon.mmochat.util.MmochatUtil;
import com.google.gson.reflect.TypeToken;

//药品:可叠加
public class MmochatDrug extends MmochatCommonObject implements
		Comparable<MmochatDrug> {
	private static final long serialVersionUID = -7234050060726772950L;

	public MmochatDrug() {
		super();
		objectType = MmochatObjectType.药品;
		canOverlap = true;
	}

	public MmochatDrug getClone() {
		return (MmochatDrug) MmochatUtil.deepClone(this, new TypeToken<MmochatDrug>() {
		}.getType());
	}

	public MmochatDrugType getType() {
		return drugType;
	}

	public void setType(MmochatDrugType type) {
		this.drugType = type;
	}

	public int getNum() {
		return overlapNum;
	}

	public void setNum(int num) {
		this.overlapNum = num;
	}

	public void addNum(int add) {
		overlapNum += add;
		overlapNum = Math.min(overlapNum,
				MmochatConstant.maxNumToOverlapOfPackage);
		overlapNum = Math.max(overlapNum, 0);
	}

	@Override
	public int compareTo(MmochatDrug drug) {
		if (drugType.getBlood() > 0 && drug.getType().getBlood() > 0) {
			return drug.getType().getBlood() - drugType.getBlood();
		} else if (drugType.getSprit() > 0 && drug.getType().getSprit() > 0) {
			return drug.getType().getSprit() - drugType.getSprit();
		} else {
			return drug.getType().getBlood() + drug.getType().getSprit()
					- drugType.getBlood() - drugType.getSprit();
		}
	}
}
